<%
System.out.println("======== Total Time Consumption for Problem Solving by Case =========");
//--------------------------------------------------------------------------------->
//
// Copyright 2002 e Professional Corporation.  All Rights Reserved.
//
// File:       	CFHDRPRP03_excel.jsp
//
// Author:   	Udong
//
// Start Date:	02/02/48
//
// Finish Date: XX/XX/XXXX 
//
// Update Date : xx/xx/xxxx by Who
// ............????????..........
//--------------------------------------------------------------------------------->
%>
<HTML>
<HEAD>
<STYLE>
.titleNormal{
	font-family: Cordia ;
	font-size:11px;
	font-weight:normal;
}
</STYLE>
<%@ page 
		language			="java"
		import				="java.util.Vector,java.util.Date,
										com.softplus.carrefour.hd.CFHDSystem,
										com.softplus.carrefour.hd.bltier.report.ICaseReportViewer,
										com.softplus.carrefour.hd.bltier.report.CCaseReportManage,
										com.softplus.carrefour.hd.bltier.entity.CfhdCaseHead,
										java.util.GregorianCalendar,
										java.text.SimpleDateFormat,
										com.softplus.carrefour.hd.bltier.util.DateUtil,
										com.softplus.carrefour.hd.bltier.entity.UserAccount,
										com.softplus.carrefour.hd.bltier.admin.ICountryViewer,
										com.softplus.carrefour.hd.bltier.admin.CountryManage,
										com.epro.standard.frontend.util.ShowData"
%>
<%	//contentType	="application/vnd.ms-excel; charset=windows-874"
		response.setHeader("Content-disposition", "inline;filename=CFHDRPRP03_excel.xls"); 
		response.setContentType("application/vnd.ms-excel");   
%>
<%@taglib uri="../WEB-INF/HeadTag.tld" prefix="head"%>
<head:Head
		title				="Report Total Time Consumption for Problem Solving by Case"
		styleFile	="../theme/defaultTheme.css,../theme/CFRLTheme.css,../theme/CFHDReportTheme.css"></head:Head>
</HEAD>
<%System.out.println("1");
  	ShowData showData 	= new ShowData();
// === define variable ===
		String	selectWidth		= "155";
		String	tableWidth			= "750";
		String[]	columnWidth		= {"200","155","70","70","70","80","30"};
System.out.println("2");
		String	countryID				= request.getParameter("country")==null? "":request.getParameter("country");
		String	countryName		= "";

		String	caseType			=      "";//"";
		String	caseType1			= request.getParameter("caseP1")==null? "":request.getParameter("caseP1");//"P1";//
		String	caseType2			= request.getParameter("caseP2")==null? "":request.getParameter("caseP2");//"P2";//
		String	caseType3			= request.getParameter("caseP3")==null? "":request.getParameter("caseP3");//"P3";//
		String	caseType4			= request.getParameter("caseP4")==null? "":request.getParameter("caseP4");//"P4";//

		//		if ( !caseType1.equals("") && !caseType2.equals("") && !caseType3.equals(""))
//		{		caseType	=	"ALL";		}
System.out.println("3");
		SimpleDateFormat	simpDF	=	new SimpleDateFormat("dd/MM/yy");
		String	fromDateStr		= request.getParameter("fromDate")==null?"":request.getParameter("fromDate");
		String	toDateStr				= request.getParameter("toDate")==null?"":request.getParameter("toDate");
		System.out.println(caseType1+caseType2+caseType3);
System.out.println("4"+request.getParameter("caseP1"));
		//GregorianCalendar	cal	= new GregorianCalendar();
		//cal.clear();
        //cal.set(2004,0,1);
		Date		fromDate				= new SimpleDateFormat("dd/MM/yyyy").parse(fromDateStr);//cal.getTime();//        Date d1 = cal.getTime(); 
        //cal.set(2005,0,30);
		Date		toDate					= new SimpleDateFormat("dd/MM/yyyy").parse(toDateStr);//cal.getTime();//        Date d2 = cal.getTime(); 
		//System.out.println("..."+fromDate+"...."+toDate+"....."+new SimpleDateFormat("dd/MM/yyyy").format(toDate));

		//String	showCaseType = "";
		int			grandTotal	= 0;
// === define object ===
		ICaseReportViewer		reportManage	=	(CCaseReportManage)CFHDSystem.getControlClass("CASE_REPORT");

		ICountryViewer					countryManage	=	(CountryManage)CFHDSystem.getControlClass("COUNTRY");
		if  (!(countryID.equals("ALL")))
		{		countryName	=	countryManage.getCountry(countryID).getCountryName();		}
		else
		{		countryName	=	"ALL";		}

		UserAccount					userSession		=  (UserAccount) request.getSession().getAttribute("userVO");//"kunlaporn_c";
		String								userID					= userSession.getUserId();//"admin";//userVO.getUserId();//request.getParameter("uid");
		System.out.println("----"+userID);
// === define vector ===
		Vector	reportVector	=	new Vector(0);
%>
<BODY style="overflow: auto;">

<script src="../script/spToolbar.js" type="text/javascript"></script>

<DIV align="center" id="masterZone" style="height:150px; overflow-x: hidden; overflow-y: hidden;">
<TABLE width="<%=tableWidth%>" cellspacing="0" cellpadding="0" border="0" bordercolor="red">
	<TR>
			<TD>
					<DIV class="Header">E-Helpdesk</DIV>
					<DIV class="Header">Total Time Consumption for Problem Solving by Case</DIV>
					<DIV class="viewCaseHeader"  style="text-align: right;">Create Date: 
																						<%=new SimpleDateFormat("dd/MM/yyyy HH:mm").format(DateUtil.getLocalDate(userID))%></DIV>
					<DIV class="viewCaseHeader">Country: <%=countryName%></DIV>
					<DIV class="viewCaseHeader">Case Type: <% if (caseType1.equals("P1")){%> User Question(P1)<%}%>
																												<% if (caseType2.equals("P2")){%> Problem Report(P2)<%}%>
																												<% if (caseType3.equals("P3")){%> Change Request(P3)<%}%>
																												<% if (caseType4.equals("P4")){%> Change Request(P4)<%}%>
																												</DIV>
					<DIV class="viewCaseHeader">Open Case Date From: 
															<%=new SimpleDateFormat("dd/MM/yyyy").format(fromDate)%> 
															To: <%=new SimpleDateFormat("dd/MM/yyyy").format(toDate)%></DIV>
			</TD>
	</TR>
	<TR>
			<TD>
					<TABLE width="740" cellspacing="0" cellpadding="0" border="0" bordercolor="blue" bgcolor="darkorange">
						<TR>
							<TD class="titleFont" style="text-align: center; color: white;" width="<%=columnWidth[0]%>">Case ID</TD>
							<TD class="titleFont" style="text-align: center; color: white;" width="<%=columnWidth[1]%>">Subject</TD>
							<TD class="titleFont" style="text-align: center; color: white;" width="<%=columnWidth[2]%>">Open Case Country</TD>
							<TD class="titleFont" style="text-align: center; color: white;" width="<%=columnWidth[3]%>">Open Case Date</TD>
							<TD class="titleFont" style="text-align: center; color: white;" width="<%=columnWidth[4]%>">Closed Case Date</TD>
							<TD class="titleFont" style="text-align: center; color: white;" width="<%=columnWidth[5]%>">Total Time(Day(s))</TD>
							<TD class="titleFont" style="text-align: center; color: white;" width="<%=columnWidth[6]%>">Case Type</TD>
						</TR>
					</TABLE>
			</TD>
	</TR>
</TABLE>
</DIV>

<DIV align="center" id="dataZone" style="overflow-x: hidden;overflow-y: hidden;">
<TABLE width="<%=tableWidth%>" cellspacing="0" cellpadding="0" border="0" bordercolor="yellow">
<%
		// loop for :- loop of case type. 
		for (int i=1; i<5; i++)
		{
			String	caseTypeLoop	=	"caseType"+i;
			//if (!caseTypeLoop.equals("")){
			if (caseTypeLoop.equals("caseType1"))
				{	caseType	=	caseType1;	}
			else if (caseTypeLoop.equals("caseType2"))
				{	caseType	=	caseType2;	}
			else if (caseTypeLoop.equals("caseType3"))
				{	caseType	=	caseType3;	}
			else if (caseTypeLoop.equals("caseType4"))
			{	caseType	=	caseType4;	}

			if (!(caseType.equals("")))
			{	
				//System.out.println("..."+countryID+"..."+caseType+"..."+caseType2+"..."+caseType3+"..."+fromDate+"..."+toDate+"...");
				reportVector	=	reportManage.listTotalTimeConsume(countryID,caseType,fromDate,toDate);//("81","P1",new Date(104,0,1),new Date(105,11,31));
				grandTotal		=	grandTotal+reportVector.size();

				for(int k=0;k<reportVector.size();k++)
				{		CfhdCaseHead		reportEntity	=	(CfhdCaseHead)reportVector.elementAt(k);
%>	
	<TR>
			<TD>
					<TABLE width="740" cellspacing="0" cellpadding="0" border="0" bordercolor="pink">
						<TR>
							<TD class="resultFont" width="<%=columnWidth[0]%>"><%=showData.CheckNull(reportEntity.getCaseId())%></TD>
							<TD class="resultFont" width="<%=columnWidth[1]%>"><%=showData.CheckNull(reportEntity.getSubject())%></TD>
							<TD class="resultFont" width="<%=columnWidth[2]%>"><%=showData.CheckNull(reportEntity.getCountry().getCountryName())%></TD>
							<TD class="resultFont" width="<%=columnWidth[3]%>" style="text-align: center;">
												<%="&nbsp;"+showData.CheckNull(reportEntity.getOpenCaseDate(),"dd/MM/yy")%></TD>
							<TD class="resultFont" width="<%=columnWidth[4]%>" style="text-align: center;">
												<%="&nbsp;"+showData.CheckNull(reportEntity.getCloseCaseDate(),"dd/MM/yy")%></TD>
							<TD class="resultFont" width="<%=columnWidth[5]%>" style="text-align: center;"><%=showData.CheckNull(reportEntity.getDuration())%></TD>
							<TD class="resultFont" width="<%=columnWidth[6]%>" style="text-align: center;"><%=showData.CheckNull(reportEntity.getCaseType())%></TD>
						</TR>
					</TABLE>
			</TD>
	</TR>
<%
				}// end FOR write all data.
			}//end if each case type is selected
		//}//end if caseTypeLoop is selected
		}//end FOR loop
%>
	<TR>
			<TD style="border-top: solid 2px #FF8C00">
					<TABLE cellspacing="0" align="right" border="0" bordercolor="green">
						<TR >
							<TD>&nbsp;</TD>
							<TD>&nbsp;</TD>
							<TD>&nbsp;</TD>
							<TD>&nbsp;</TD>
							<TD class="TotalByCaseTyephaveline" width="150">Grand Total</TD>
							<TD class="TotalByCaseTyephaveline"><%=grandTotal%></TD>
							<TD class="TotalByCaseTyephaveline">Cases</TD>
						</TR>
					</TABLE>
			</TD>
	</TR>
</TABLE>
</DIV>
</BODY>
</HTML>